package com.supermap.dataservice.deviceinfo;

import com.supermap.dataservice.deviceinfo.dao.DeviceinfoDao;
import com.supermap.dataservice.util.JSONUtil;
import com.supermap.dubbo.api.deviceinfo.DeviceinfoService;
import com.supermap.dubbo.api.deviceinfo.entity.Deviceinfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.dubbo.config.annotation.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:langhongshuai
 * @Description:设备业务逻辑层
 * @Date:18/5/14 下午4:25
 */
@Service
public class DeviceinfoServiceImpl implements DeviceinfoService {

    /**
     *使用指定类初始化日志对象，在日志输出的时候，可以打印出日志信息所在类
     */
    protected static final Logger logger = LoggerFactory.getLogger(DeviceinfoServiceImpl.class);


    @Resource
    private DeviceinfoDao deviceinfoDao;

    @Override
    public JSONUtil getAllDeviceInfo() {
        //初始化Json封装工具类
        JSONUtil jsonUtil = new JSONUtil();
        try {
            //获得所有的设备信息
            List<Deviceinfo> deviceinfos = deviceinfoDao.getAllDeviceInfo();

            //获得所有的设备信息后返回的json数据
            jsonUtil.setMsg("Get all deviceinfo success！");
            jsonUtil.setIsSuccess(true);
            jsonUtil.setCode(200);
            jsonUtil.setData(deviceinfos);
        }catch (Exception e) {
            //捕捉数据库异常
            logger.error("DeviceinfoServiceImpl=>getAllDeviceInfo=>DaoException:"+e.getMessage());
            jsonUtil.setMsg("Get all deviceinfo flase！");
            jsonUtil.setIsSuccess(false);
            jsonUtil.setCode(100);
        }
        return jsonUtil;
    }

    @Override
    public JSONUtil getDeviceInfosByParkId(int parkId) {
        //初始化Json封装工具类
        JSONUtil jsonUtil = new JSONUtil();
        try {
            //通过园区id获得设备信息
            List<Deviceinfo> deviceinfos = deviceinfoDao.getDeviceInfosByParkId(parkId);

            //获得设备信息后返回的json数据
            jsonUtil.setMsg("Get deviceinfos success！");
            jsonUtil.setIsSuccess(true);
            jsonUtil.setCode(200);
            jsonUtil.setData(deviceinfos);
        }catch (Exception e) {
            //捕捉数据库异常
            logger.error("DeviceinfoServiceImpl=>getDeviceInfosByParkId=>DaoException:"+e.getMessage());
            jsonUtil.setMsg("Get deviceinfos flase！");
            jsonUtil.setIsSuccess(false);
            jsonUtil.setCode(100);
        }
        return jsonUtil;
    }
}
